<?php
	/**
	* Bill Manager - Add Log for selected bill
	* @author: trungdt
	* @since: Oct 22, 2011
	* @version: 1.0
	* 
	*  
	* Change logs
	*/
	if (!defined('EXPONENT')) exit('');
    
    if (!exponent_users_isLoggedIn())
        die();
    
    $have_permission=false;
    if (exponent_users_isAdmin() || exponent_permissions_check(array('administrate', "bill_management"),$loc))
        $have_permission=true;

    if ($have_permission && isset($_REQUEST['note']) && isset($_REQUEST['id']))
    {
        $id=intval($_REQUEST['id']);
        $note=_ab_safe_html_string($_REQUEST['note']);
        
        productsmodule::__Bill_AddLogs("User {$user->firstname} {$user->lastname} ({$user->username}) add comment of this bill: {$note}", $id);

        // send email to admin 
        $headers['From'] =  SMTP_FROMADDRESS ;
        $headers['Reply-to'] = SMTP_FROMADDRESS;
        require_once(BASE.'subsystems/mail.php');
        $mail = null;
        $mail = new exponentMail();

        $mail->addTo(SMTP_FROMADDRESS);
        $mail->subject("Notification: User {$user->firstname} {$user->lastname} ({$user->username}) add comment of bill #{$id}: {$note}");
        $mail->addText("Notification: User {$user->firstname} {$user->lastname} ({$user->username}) added bill #{$id} log: at ".date('F j, Y, H:i:s',aboid_getCurrentTime()).". The log content is: '{$note}'. This request sent from IP Address ".$_SERVER['REMOTE_ADDR'].". Thanks.");
        $mail->addHeaders($headers);
        $mail->addFrom(SMTP_FROMADDRESS, SITE_TITLE );
        @$mail->send();
        
        echo exponent_lang_getText("bill_add_log_success");
    }
    exponent_theme_setFlagAjaxAction(true);
?>
